package com.jl15988.simpletools.system.controller;

import com.jl15988.simpletools.common.annotation.Log;
import com.jl15988.simpletools.common.constant.OperationType;
import com.jl15988.simpletools.common.utils.Result;
import com.jl15988.simpletools.system.service.DashboardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 仪表盘控制器
 *
 * @author jl15988
 */
@Slf4j
@Api(tags = "仪表盘接口")
@RestController
@RequestMapping("/api/v1/dashboard")
public class DashboardController {

    @Autowired
    private DashboardService dashboardService;

    @Log(title = "获取仪表盘数据", operationType = OperationType.QUERY)
    @ApiOperation("获取仪表盘数据")
    @GetMapping("/data")
    @PreAuthorize("hasAnyRole('ADMIN')")
    public Result<Map<String, Object>> getDashboardData() {
        log.info("获取仪表盘数据");
        Map<String, Object> data = dashboardService.getDashboardData();
        return Result.success(data);
    }

    @Log(title = "获取下载趋势", operationType = OperationType.QUERY)
    @ApiOperation("获取下载趋势")
    @GetMapping("/download-trend")
    @PreAuthorize("hasAnyRole('ADMIN')")
    public Result<List<Map<String, Object>>> getDownloadTrend(
            @ApiParam(value = "时间范围：week-本周, month-本月, year-全年", required = true)
            @RequestParam String timeRange) {
        log.info("获取下载趋势，时间范围：{}", timeRange);
        List<Map<String, Object>> data = dashboardService.getDownloadTrend(timeRange);
        return Result.success(data);
    }
} 